package com.core.image.core.frames;

import com.core.image.core.IoArgs;

/**
 * describe:
 *
 * @author 库琦
 * @date 2020/01/31/0:13
 */
public class ReceiveFrameFactory {
    public static AbsReceiveFrame createInstance(IoArgs ioArgs){
        byte[] buffer = new byte[Frame.FRAME_HEADER_LENGTH];
        ioArgs.writeTo(buffer,0);
        byte type = buffer[2];
        switch (type){
            case Frame.TYPE_COMMAND_SEND_CANCEL:
                return new CancelReceiveFrame(buffer);
            case Frame.TYPE_PACKET_HEADER:
                return new ReceiveHeaderFrame(buffer);
            case Frame.TYPE_PACKET_ENTITY:
                return new ReceiveEntityFrame(buffer);
            case Frame.TYPE_COMMAND_HEARTBEAT:
                return HeartbeatReceiveFrame.INSTANCE;
            default:
                throw new UnsupportedOperationException("Unsupported frame type:" + type);
        }
    }
}
